<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>  
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>合同方案列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">

	<div class="searchArea">
		<form id="searchBar">
			<div class="fieldset1 tabel_col clearFix">
				<div class="fieldBox col_33">
					<div class="label">合同编码</div>
					<div class="field">
						<input name="contCd" id="contCd" type="text" class="ui-textbox"/>
					</div>
				</div>
				<div class="fieldBox col_33" >
					<div class="label">合同名称</div>
					<div class="field">
						<input name="contNm" id="contNm" type="text" class="ui-textbox"/>
					</div>
				</div>
				<div class="fieldBox col_33" >
					<div class="label">合同类型</div>
					<div class="field">
						<input type="text" id="contTyp" name="contTyp" ltype="combobox" placeholder="请选择"/>
					</div>
				</div>
			</div>
		</form>
	</div>
	<div class="btnsBox">
		<span id="searchBtn"  class="sq-button sq-button-round" onclick="search()">查询</span>
		<span id="clearBtn" class="sq-button sq-button-round" onclick="clearSearchBar()">清空</span>
	</div>
	<div id="ligergrid" class="sq-grid"></div>
	<div class="btnsBox">
		<span id="addBtn"  class="sq-button sq-button-round" onclick="saveSelected()">保存</span>
		<span id="cacelBtn"  class="sq-button sq-button-round" onclick="closeDialog()">取消</span>
	</div>
</div>


<script type="text/javascript">

	var dialog = window.frameElement.dialog;
	
    $(function () {
    	init();
		initGrid();
		initForm();
    });

	function init(){
		// 项目类型
		$("#contTyp").ligerComboBox({
			url:'<%=path%>/system/sysdictionary/getSysDic.do',
			ajaxType:'GET',
			parms:{ orgCd: "0000", sysCd: "11000",codeGroup:"CONT001" },
			valueField: 'key',
			textField:'value'
		});
	}
	
	function initForm(){
		form = $("#searchBar").ligerForm();
	}

    function initGrid() {

		grid = $("#ligergrid").ligerGrid({
			url: '<%=path%>/cont/config/initList.do',
			method: 'get',
			parms:function(){
				return $("#searchBar").ligerForm().getData();
			},
			columns: [
				{display: '合同编码', name: 'contCd',width:100},
				{display: '合同名称', name: 'contNm',align:'left'},
				{display: '合同描述', name: 'contDesc',align:'left'},
				{display: '合同类型', name: 'contTypNm',width:80},
				{display: '操作',width:80,
					render:function (rowdata, rowindex, value, column) {
						if(rowdata.isVal){
							return "<a href='javascript:void(0)' onclick='showDialog(\""+rowdata.valRule+"\",\""+rowindex+"\")'>取值</a>";
						}
					}
				}
			],
			root: 'rows',
            record: 'total',
			height:400,
			checkbox:true,//列表是否有选择框
            rownumbers:true//列表是否有行号
		});
		//grid.setHeight(100);
	}

	function search(){
		grid.reload();
	}

	function clearSearchBar(){
		clearLigerForm("searchBar");
	}


	function saveSelected() {
		// 必须选择至少一条
		var rows = grid.getSelectedRows();
		if(rows.length<1){
			top.$.ligerDialog.SQalert({content: "请先选择数据",SQ_type: "error"});
			return;
		}
		var cfgCd = dialog.get('data').cfgCd;//获取data参数
		console.log(rows);
		var formData = new Array(rows.length);
		for(var i=0;i<rows.length;i++){
			var data = {};
			data.cfgCd=cfgCd;
			data.contCd=rows[i].contCd;
			if(rows[i].isVal){
				if(!rows[i].contKv){
					top.$.ligerDialog.SQalert({content: "请先录入取值信息，行号 "+(rows[i].__index+1),SQ_type: "error"});
					return;
				}
				data.contKv=rows[i].contKv;
			}
			formData[i]=data;
		}
		console.log(formData);
		
		// 所选值必须完备

		var wait_dialog;
		$.ajax({
			type: 'post',
			contentType:'application/json',
			dataType:'json',
			data:JSON.stringify(formData),
			url: '<%=path%>/cont/prj/bindCont.do',
			beforeSend: function () {
				wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
					
					var callback = dialog.get('data').callback;
					if(callback){
						callback();
					}
					dialog.close();
				}else{
					top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
				}
			},
			error:function () {
				wait_dialog.close();
				top.$.ligerDialog.SQalert({content: "系统错误，请稍后重试",SQ_type: "error"});
			}
		});

	}


	

	function showRuleCfg(ruleValue,index){
		activeIndex = index;
		if("zgshBcxy"==ruleValue){
			dialog = $.ligerDialog.open({ titile:"ZGSH补充协议",target: $("#"+ruleValue) ,width:400,height:300});
		}else if("zgshZlzfb"==ruleValue){
			dialog = $.ligerDialog.open({ titile:"ZGSH租赁支付表",target: $("#"+ruleValue) ,width:400,height:300});
		}else if("zgshMM"==ruleValue){
			dialog = $.ligerDialog.open({ titile:"ZGSH买卖合同",target: $("#"+ruleValue) ,width:400,height:300});
		}
	}
	
	function showDialog(ruleValue,index){
		var rtitle = "";
		if("zgshBcxy"==ruleValue){
			rtitle="ZGSH补充协议";
		}else if("zgshZlzfb"==ruleValue){
			rtitle="ZGSH租赁支付表";
		}else if("zgshMM"==ruleValue){
			rtitle="ZGSH买卖合同";
		}
		$.ligerDialog.open({
            height:350,
            width: 450,
            title : rtitle,
            url: '<%=path%>/cont/prj/toContKvPage.do?rule='+ruleValue, 
            showMax: false,
            showToggle: true,
            showMin: false,
            isResize: true,
            slide: false,
            data: {
            	contCd : grid.getRow(index).contCd,
                callback:function(val){
                	grid.getRow(index).contKv=val;
                }
            }
            //自定义参数
            //myDataName: $("#txtValue").val()
        });
	}
	
	function getContent(){
		
		var zgshBcxy_c = '';
		
	}

	function closeDialog() {
		dialog.close();
	}
    

</script>

</body>
</html>